import json
import os


def test():
    writePath = 'C:/Users/wangw/Desktop/test'
    dirPath = 'C:/Users/wangw/Desktop/1'
    with open(writePath, 'w', encoding='utf-8') as f:
        files = os.listdir(dirPath)
        for filePath in files:
            url = dirPath + '/' + filePath
            print(url)
            with open(url, 'r', encoding='utf-8') as file:
                line = file.readline()
                while line:
                    time_end = line.find(' INFO')
                    json_index = line.find('[{')
                    json_str = line[json_index:]
                    json_list = json.loads(json_str)
                    obj = json_list[0]
                    str1 = line[:time_end] + ' ' + obj['bsApplyId'] + ' ' + obj['status'] + '\n'
                    f.write(str1)
                    # print(line[:time_end], obj['bsApplyId'], obj['status'])
                    line = file.readline()


def find_str():
    writePath = 'C:/Users/wangw/Desktop/test'
    dirPath = 'C:/Users/wangw/Desktop/1'
    with open(writePath, 'w', encoding='utf-8') as f:
        files = os.listdir(dirPath)
        for filePath in files:
            url = dirPath + '/' + filePath
            print(url)
            with open(url, 'r', encoding='utf-8') as file:
                line = file.readline()
                while line:
                    if line.find('"31516847"') >= 0:
                        f.write(line)
                    # print(line[:time_end], obj['bsApplyId'], obj['status'])
                    line = file.readline()


find_str()
